home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 17 / AMIGAplus Sonderheft 17 (1999)(ICP)(DE)[!].iso / Rexx / Invoice.rexx < prev    next >
OS/2 REXX Batch file  |  1998-01-13  |  6KB  |  306 lines

  1. /*
  2.         TimeKeep - Final Writer script
  3.         $VER: 13 Jan 1998 - Invoice.rexx
  4. */
  5.  
  6. options results
  7.  
  8. /* Initialize */
  9. 'CopyRuler'
  10. Tab = '09'x
  11. Quote = '22'x
  12. cInvoice = 0
  13.  
  14. DataPath = "S:TimeKeep/"
  15.  
  16. 'RequestText' '"Create Invoice" "ENTER Client Code" ""'
  17. iNameCode = RESULT
  18.  
  19. if iNameCode = "" | iNameCode = "RESULT" then exit
  20.  
  21. /* Read Time Data */
  22. if ~ open('Time', DataPath||iNameCode||".time", 'R') then do
  23.     'ShowMessage' 1 1 '"CREATE INVOICE ERROR" ".time NOT FOUND" "" "OK" "" ""'
  24.     exit
  25. end
  26.  
  27. t = readln('Time')
  28. parse var t '"'Client.NameCode'","'Client.Name'"'
  29.  
  30. /* Collate */
  31. Projects = "|"; nProjects = 0 ; Expenses = 0; Work = 0
  32. do while ~eof('Time')
  33.     t = readln('Time')
  34.     parse var t '"'tType'","'tProject'",'tInfo
  35.  
  36.     if tInfo == "" then leave
  37.  
  38.     if index(Projects, "|"tProject"|") = 0 then do
  39.         /* Project not found */
  40.         Projects = Projects||tProject"|"
  41.         nProjects = nProjects + 1
  42.         Projects.nProjects.Name = tProject
  43.  
  44.         if tType = "T" then do
  45.             Projects.nProjects.count = 1
  46.             Expenses.nProjects.count = 0
  47.             end
  48.         else do
  49.             Projects.nProjects.count = 0
  50.             Expenses.nProjects.count = 1
  51.         end
  52.  
  53.         cProject = nProjects; n = 1
  54.         end
  55.     else do
  56.         /* Project exists */
  57.         do lp = 1 to nProjects
  58.             if Projects.lp.Name = tProject then leave
  59.         end
  60.         cProject = lp
  61.  
  62.         if tType = "T" then do
  63.             Projects.lp.count = Projects.lp.count + 1
  64.             n = Projects.lp.count
  65.             end
  66.         else do
  67.             Expenses.lp.count = Expenses.lp.count + 1
  68.             n = Expenses.lp.count
  69.         end
  70.     end
  71.  
  72.     if tType = "T" then do
  73.         Projects.cProject.n.Info = tInfo
  74.         Work = 1
  75.         end
  76.     else do
  77.         Expenses.cProject.n.Info = tInfo
  78.         Expenses = 1
  79.     end
  80. end
  81.  
  82. call close('Time')
  83.  
  84. if nProjects = 0 then do
  85.     'ShowMessage' 1 1 '"CREATE INVOICE ERROR" "NO Logged Time or Expenses" "" "OK" "" ""'
  86.     exit
  87. end
  88.  
  89. /* Read Invoice Number */
  90. if open('Invoice', DataPath||Client.NameCode||".invoice", 'R') then do
  91.     cInvoice = readln('Invoice')
  92.     call close('Invoice')
  93. end
  94.  
  95. cInvoice = cInvoice + 1
  96.  
  97. Client.Invoice = right(cInvoice, 2, "0")
  98.  
  99. /* Create Invoice */
  100.  
  101. 'Justify' CENTER
  102.  
  103. /* Invoice # */
  104. 'Font' "SoftSans_Bold"; 'FontSize' 24
  105. 'Type' "Invoice #"Client.NameCode''Client.Invoice
  106.  
  107. 'NewParagraph'
  108.  
  109. /* Client Name */
  110. 'Font' "SoftSans_Bold"; 'FontSize' 14
  111. 'Type' Client.Name
  112.  
  113. 'NewParagraph'; 'NewParagraph'
  114. 'Justify' RIGHT
  115.  
  116. /* Date */
  117. 'Font' "SoftSans_Bold"; 'FontSize' 12
  118. 'Insert' DATE
  119.  
  120. 'NewParagraph'
  121. 'Justify' CENTER
  122. 'NewParagraph'
  123.  
  124. /* Work Description */
  125. 'Font' "SoftSans_Bold"; 'FontSize' 18
  126. 'Type' "Work"
  127.  
  128. 'NewParagraph'
  129. 'Justify' LEFT
  130.  
  131. /* Work Description - Projects */
  132.  
  133. do lp = 1 to nProjects
  134.     if Projects.lp.Name ~= "" then do
  135.         'PasteRuler'
  136.         'Font' "SoftSans_Bold"; 'FontSize' 12
  137.         'Type' Projects.lp.Name
  138.         'NewParagraph'
  139.  
  140.         'SetTab' .125 LEFT
  141.         'Font' "SoftSans"; 'FontSize' 12
  142.         'Type' tab"· "
  143.         'NewParagraph'
  144.     end
  145. end
  146.  
  147.  
  148. /* Expenses */
  149. TotalExpenses = 0
  150. if Expenses then do
  151.     'Justify' CENTER
  152.     'NewParagraph'
  153.     'Font' "SoftSans_Bold"; 'FontSize' 18
  154.     'Type' "Expenses"
  155.  
  156.     'NewParagraph'
  157.     'Justify' LEFT
  158.  
  159.     do lp = 1 to nProjects
  160.         if Expenses.lp.count = 0 then iterate
  161.  
  162.         'PasteRuler'
  163.         'Font' "SoftSans_Bold"; 'FontSize' 12
  164.         'Type' Projects.lp.Name
  165.         'NewParagraph'
  166.  
  167.         'Font' "SoftSans"; 'FontSize' 12
  168.         'SetTab' .125 LEFT; 'SetTab' 6.0 DECIMAL
  169.         do lp2 = 1 to Expenses.lp.count
  170.             t = Expenses.lp.lp2.Info
  171.             if index(t, '","', index(t, '","')+3) = 0 then do
  172.                 parse var t '"'tInfo'","'tAmount'"'
  173.                 'Type' tab''tInfo''tab''tAmount
  174.                 end
  175.             else do
  176.                 parse var t '"'tInfo'","'tQuantity'","'tPer'","'tAmount'"'
  177.                 'Type' tab''tInfo" ("tQuantity" @ "tPer")"tab''tAmount
  178.             end
  179.  
  180.             'NewParagraph'
  181.             TotalExpenses = TotalExpenses + tAmount
  182.         end
  183.     end
  184.  
  185.     'PasteRuler'
  186.     'SetTab' 5.0 RIGHT; 'SetTab' 6.0 DECIMAL
  187.  
  188.     'Font' "SoftSans_Bold"; 'FontSize' 14
  189.     'Type' Tab"Expenses"Tab"$"TotalExpenses
  190.  
  191.     'NewParagraph'
  192.     'PasteRuler'
  193. end
  194.  
  195.  
  196. Total = 0
  197. if Work then do
  198.     'Justify' CENTER
  199.     'NewParagraph'
  200.     /* Work Hours */
  201.     'Font' "SoftSans_Bold"; 'FontSize' 18
  202.     'Type' "Work Hours"
  203.  
  204.     'NewParagraph'
  205.     'Justify' LEFT
  206.  
  207.     do lp = 1 to nProjects
  208.         if Projects.lp.count = 0 then iterate
  209.  
  210.         'PasteRuler'
  211.         'Font' "SoftSans_Bold"; 'FontSize' 12
  212.         'Type' Projects.lp.Name
  213.         'NewParagraph'
  214.  
  215.         'SetTab' .6875 RIGHT; 'SetTab' 1.5625 RIGHT; 'SetTab' 1.625 LEFT
  216.         'SetTab' 2.4375 RIGHT; 'SetTab' 2.8125 DECIMAL
  217.         'SetTab' 4.0625 RIGHT; 'SetTab' 4.9375 RIGHT; 'SetTab' 5.0 LEFT
  218.         'SetTab' 5.8125 RIGHT; 'SetTab' 6.1875 DECIMAL
  219.  
  220.         'Font' "SoftSans"; 'FontSize' 11
  221.         nLeft = trunc(Projects.lp.count / 2 + .5)
  222.  
  223.         HSubTotal = 0
  224.         do lp2 = 1 to nLeft
  225.             parse var Projects.lp.lp2.Info '"'tDate'","'tT1'","'tT2'","'tH'","'tRate'"'
  226.             'Type' Tab''tDate''Tab''tT1''Tab"-"Tab''tT2''Tab''tH
  227.             'NewParagraph'
  228.             HSubTotal = HSubTotal + tH
  229.         end
  230.  
  231.         if Project.lp.count ~= 1 then do
  232.             do lp2 = 1 to nLeft; 'Cursor' UP; end
  233.             'CtrlDown'; 'AltDown'; 'Cursor' RIGHT; 'AltUp'; 'CtrlUp'
  234.             do lp2 = nLeft+1 to Projects.lp.count
  235.                 parse var Projects.lp.lp2.Info '"'tDate'","'tT1'","'tT2'","'tH'","'tRate'"'
  236.                 'Type' Tab''tDate''Tab''tT1''Tab"-"Tab''tT2''Tab''tH
  237.                 'Cursor' DOWN
  238.                 HSubTotal = HSubTotal + tH
  239.             end
  240.         end
  241.  
  242.         SubTotal = trunc(HSubTotal * tRate + .5e-2, 2)
  243.  
  244.         'Cursor' DOWN
  245.         'PasteRuler'
  246.         'SetTab' 4.0 DECIMAL; 'SetTab' 6.0 DECIMAL
  247.  
  248.         'Font' "SoftSans_Bold"; 'FontSize' 12
  249.         'Type' Tab''HSubTotal
  250.         'Font' "SoftSans"; 'FontSize' 12
  251.         'Type' " @ $"tRate" / hour"
  252.         'Font' "SoftSans_Bold"; 'FontSize' 12
  253.         'Type' Tab''SubTotal
  254.         'NewParagraph'
  255.         Total = Total + SubTotal
  256.     end
  257.  
  258.     'PasteRuler'
  259.     'SetTab' 5.0 RIGHT; 'SetTab' 6.0 DECIMAL
  260.  
  261.     'Font' "SoftSans_Bold"; 'FontSize' 14
  262.     'Type' Tab"Work"Tab"$"Total
  263. end
  264.  
  265. 'NewParagraph'; 'NewParagraph'
  266.  
  267. Total = Total + TotalExpenses
  268. 'PasteRuler'
  269. 'SetTab' 5.0 RIGHT; 'SetTab' 6.0 DECIMAL
  270. 'Font' "SoftSans_Bold"; 'FontSize' 18
  271. 'Type' Tab"Total"Tab"$"
  272. 'Style' UNDERLINE
  273. 'Type' Total
  274. 'Style' NORMAL
  275.  
  276. 'NewParagraph'
  277. 'PasteRuler'
  278. 'NewParagraph'; 'NewParagraph'
  279.  
  280. 'Type' "Payment To:"
  281.  
  282. 'NewParagraph'
  283. 'Justify' CENTER
  284.  
  285. 'Font' "SoftSans"; 'FontSize' 12
  286. 'Type' "scott dhomas trenn"
  287. 'NewParagraph'
  288. 'Type' "797 Mitchell Street, Fredericton, NB   E3B 3S8"
  289. 'NewParagraph'
  290. 'Type' "(506) 459-7088"
  291.  
  292. /* Reposition Cursor */
  293. 'CtrlDown'; 'AltDown'; 'Cursor' UP; 'AltUp'; 'CtrlUp'
  294. do lp = 1 to 7; 'Cursor' DOWN; end
  295. 'CtrlDown'; 'AltDown'; 'Cursor' RIGHT; 'AltUp'; 'CtrlUp'
  296.  
  297. /* Write Invoice Number */
  298. call open('Invoice', DataPath||Client.NameCode||".invoice", 'W')
  299. call writeln('Invoice', cInvoice)
  300. call close('Invoice')
  301.  
  302. /* Backup .time data file */
  303. ADDRESS COMMAND 'C:Rename' DataPath||Client.NameCode||".time" DataPath||Client.NameCode||".time."Client.Invoice
  304.  
  305. exit
  306.